#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
  void convertline(vector<int> &a) {
    for (auto p = a.begin(); p != a.end(); ++p) {
      *p = 1 - *p;
    }
  }
  void convertcol(vector<vector<int>> &a, int col) {
    for (auto p = a.begin(); p != a.end(); ++p) {
      (*p)[col] = 1 - ((*p)[col]);
    }
  }
  unsigned long long calc(vector<int> &a) {
    unsigned long long res = 0;
    for (auto p = a.begin(); p != a.end(); ++p) {
      res = res * 2 + (*p);
    }
    return res;
  }
  bool needconvertcol(vector<vector<int>> &a, int col) {
    unsigned long long res = 0;
    for (auto p = a.begin(); p != a.end(); ++p) {
      res += (*p)[col];
    }
    if (res * 2 < a.size())
      return true;
    return false;
  }
  int matrixScore(vector<vector<int>> &grid) {
    unsigned long long res = 0;
    for (auto p = grid.begin(); p != grid.end(); ++p) {
      if ((*p)[0] == 0) {
        convertline(*p);
      }
    }
    for (int i = 0; i < grid[0].size(); ++i) {
      if (needconvertcol(grid, i)) {
        convertcol(grid, i);
      }
    }
    for (auto p = grid.begin(); p != grid.end(); ++p) {
      res += calc(*p);
    }
    return res;
  }
};

int main (int argc, char *argv[]) {
	vector<vector<int>> a={{0,0,1,1},{1,0,1,0},{1,1,0,0}};
	Solution s;
	cout<<s.matrixScore(a);
	return 0;
}
